# include "scene.h"

#ifdef SOLVE_ENERGY
# include <stdio.h>

/* This function determines all the grid-parameters related to the heater which is fixed at the top surface. */
extern short heater_param(struct grid *g)
   {
    unsigned short i, nr;
    double *r;

    nr = g->nr[1]; r = g->r[1];
    for(i = NrG; i < NrG+nr; i++) if( (r_HEATER-r[i])*(r_HEATER-r[i+1]) <= 0) break;
    g->r_heater = r[(g->nr_heater = (r_HEATER-r[i] < r[i+1]-r_HEATER ? i:i+1)-NrG)+NrG];

    fprintf(g->lptr, "\n\n[Heater Parameters]\nr_heater: %E ---> %E\nnr_heater = %d\n", r_HEATER, g->r_heater, g->nr_heater);

#  ifdef CHECK_CONFIG
    printf("\n\n[Heater Parameters]\n\nr_heater: %E ---> %E\nnr_heater = %d\n", r_HEATER, g->r_heater, g->nr_heater);

    printf("\n\tAre the heater parameters reasonable (y/n) ? ");  fflush(stdout);
    if(getchar() != 'y')
           {
            printf("\nWARNING: With the grid-configuration parameters defined in \"scene.h\", proper grid-generation from heater's point of view does not seem to be possible. Re-define those parameters, re-compile, and then run the program again.\n\n");

            while(getchar() != '\n');
            return -1;
           }
    else while(getchar() != '\n');
#   endif

    return 1;
   }

#endif
